package edu.ycxy.poetry.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.ycxy.poetry.entity.ZhiShi;
import edu.ycxy.poetry.vo.AddKnowVo;
import edu.ycxy.poetry.vo.UpdateKnowVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author @xin
 * @createDate 2022/3/8
 * @Description
 */
@Repository
public interface ZhiShiMapper extends BaseMapper<ZhiShi> {
    //根据id倒序查询所有的知识内容
    @Select("select * from vab_zhishi order by id desc")
    List<ZhiShi> selectList();

    //根据知识的标题查询知识的详细信息
    @Select("select * from vab_zhishi where title=#{title}")
    ZhiShi selectByTitle(String title);

    // 添加知识
    @Insert("insert into vab_zhishi(title,txt) values (#{title},#{txt})")
    Integer addKnow(AddKnowVo addKnowVo);

    // 根据内容查询该知识的信息
    @Select("select * from vab_zhishi where txt=#{txt}")
    ZhiShi findOneByTxt(String txt);

    //模糊查询，根据知识的标题
    @Select("select * from vab_zhishi where title like CONCAT('%',#{title},'%')")
    List<ZhiShi> findListByTitle(String title);

    //根据id删除
    @Delete("delete from vab_zhishi where id=#{id}")
    void deleteById(Integer id);

    //根据id查询
    @Select("select * from vab_zhishi where id=#{id}")
    ZhiShi findOneById(Integer id);

    @Update("update vab_zhishi set title=#{title},txt=#{txt} where id=#{id}")
    Integer updateKnowById(UpdateKnowVo updateKnowVo);
}
